﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace LevelEditor.Utils
{
    public class ConvertUriToImage : IValueConverter
    {
        // Methods
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }
            if (((Uri)value).OriginalString.Contains(".mp3"))
            {
                return null;
            }
            BitmapImage bImage = new BitmapImage();
            bImage.BeginInit();
            bImage.UriSource = new Uri(FileUtil.AppStartUpPath + ((Uri)value).OriginalString);
            bImage.CacheOption = BitmapCacheOption.OnLoad;
            bImage.EndInit();
            return bImage;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


}
